package io.github.veigara.tcp.device.protocol.charger;

/**
 * @author : zhouhx
 * @date : 2025/6/6 11:26
 */

import io.github.veigara.tcp.framework.model.DeviceConnection;
import io.github.veigara.tcp.framework.protocol.ProtocolHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 充电机协议处理器
 */
public class ChargingPileProtocolHandler implements ProtocolHandler {
    private static final Logger logger = LoggerFactory.getLogger(ChargingPileProtocolHandler.class);
    private DeviceConnection deviceConnection;


    public ChargingPileProtocolHandler(DeviceConnection deviceConnection) {
        this.deviceConnection = deviceConnection;
    }

    @Override
    public void handleMessage(Object message) {
        if (message instanceof ChargingPileMessage) {
            ChargingPileMessage cpMessage = (ChargingPileMessage) message;
            logger.info("Handling charging pile message: {}", cpMessage);
            // 测试发送消息
            ChargingPileSendMessage obj = new ChargingPileSendMessage(cpMessage.getCmd(), new byte[]{});
            sendMessage(obj);
//            switch (cpMessage.getMessageType()) {
//                case HEARTBEAT:
//                    handleHeartbeat(cpMessage);
//                    break;
//                case STATUS:
//                    handleStatus(cpMessage);
//                    break;
//                case ALARM:
//                    handleAlarm(cpMessage);
//                    break;
//                default:
//                    logger.warn("Unhandled message type: {}", cpMessage.getMessageType());
//            }
        } else {
            logger.warn("Unsupported message type: {}", message.getClass());
        }
    }

    @Override
    public void setDeviceConnection(DeviceConnection connection) {
        this.deviceConnection = connection;
    }

    @Override
    public DeviceConnection getDeviceConnection() {
        return deviceConnection;
    }
}
